# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=setuptools-scm
pkgbase="python-${_realname}"
pkgname=("python3-${_realname}" "python2-${_realname}")
pkgver=3.3.3
pkgrel=1
pkgdesc="Handles managing your python package versions in scm metadata"
arch=('any')
license=('MIT')
url='https://github.com/pypa/setuptools_scm'
makedepends=('python3-setuptools' 'python2-setuptools')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname/-/_}-${pkgver}.tar.gz"
        0001-python-setuptools-scm-3.1.0-fix-path-error.patch)
sha256sums=('bd25e1fb5e4d603dcf490f1fde40fb4c595b357795674c3e5cb7f6217ab39ea5'
            '3a936600ebceccf2315fe76a79e90e4fdcfe2a936b442f6321b2d76a8e9902b1')

prepare() {
  cd ${srcdir}/${_realname/-/_}-${pkgver}
  patch -p1 -i ${srcdir}/0001-python-setuptools-scm-3.1.0-fix-path-error.patch
  cd ..

  for pver in {2,3}; do 
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname/-/_}-${pkgver}" "python${pver}-build-${CARCH}"
  done
}

package_python3-setuptools-scm() {
  depends=('python3')

  cd "${srcdir}"/python3-build-${CARCH}
  python3 setup.py install --prefix=/usr --root="${pkgdir}" --optimize=1

  install -Dm644 "LICENSE" "${pkgdir}/usr/share/licenses/python3-${_realname}/LICENSE"
}

package_python2-setuptools-scm() {
  depends=('python2')

  cd "${srcdir}"/python2-build-${CARCH}
  python2 setup.py install --prefix=/usr --root="${pkgdir}" --optimize=1

  install -Dm644 "LICENSE" "${pkgdir}/usr/share/licenses/python2-${_realname}/LICENSE"
}
